﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DbMapping;
using VideoCache.Server.Model;

namespace VideoCache.Server.DAL
{
    public partial class EpisodeDAL
    {
        public static List<EpisodeInfo> GetDownloadEpisodes()
        {
            string sql = "SELECT T_Episode.* FROM T_Episode INNER JOIN T_Album_SITE ON T_Episode.AlbumId=T_Album_Site.AlbumId AND T_Episode.SiteId=T_Album_Site.SiteId ORDER BY AlbumId, EpisodeIndex";

            DataTable dt = DbAccess.ExecuteDataTable(sql, System.Data.CommandType.Text);

            List<EpisodeInfo> list = new List<EpisodeInfo>();

            foreach (DataRow row in dt.Rows)
            {
                list.Add(GetModel(row));
            }

            return list;
        }

        public static void SetDownload(int[] list)
        {
            string sql = "UPDATE t_episode set AllowDownload=1 WHERE Id IN ({0})";

            string ids = string.Empty;

            foreach (int id in list)
            {
                if (!string.IsNullOrEmpty(ids))
                {
                    ids += ",";
                }
                ids += id;
            }

            DbAccess.ExecuteNonQuery(string.Format(sql, ids), CommandType.Text);
        }
    }
}
